//
//  Utils.m
//  gdemm
//
//  Created by yongwu on 15/12/1.
//  Copyright © 2015年 goldensoft. All rights reserved.
//

#import "Utils.h"
@implementation Utils
+(UIColor*)UIColorFromHex:(NSInteger)colorInHex{
    return [UIColor colorWithRed:((float) ((colorInHex & 0xFF0000) >> 16)) / 0xFF
                           green:((float) ((colorInHex & 0xFF00)   >> 8))  / 0xFF
                            blue:((float)  (colorInHex & 0xFF))            / 0xFF
                           alpha:1.0];
}

+ (UIColor *)colorWithKey:(NSString *)key{
    BOOL flag = [[UserDefaultsUtil shareInstance]getBool:SKIN_SWITCH];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"Skin" ofType:@"plist"]];
    if (dict == nil) {
        return nil;
    }
    
    NSDictionary *skinDict;
    if (flag) {
        skinDict = dict[@"wdblue"];
        
    }else{
        skinDict = dict[@"hlblue"];
    }
    
    NSString *colorStr = skinDict[key];
    NSArray *colorArr = [colorStr componentsSeparatedByString:@","];
    if (colorArr == nil || colorArr.count != 3) {
        return nil;
    }
    
    return HRColor([colorArr[0] doubleValue], [colorArr[1]doubleValue], [colorArr[2] doubleValue]);
    
}
+(UIImage *)getImageByDevce:(NSString *)imageName{
    UIImage * img;
    if ([DeviceTypeJudge isPadDeviceType]) {
        img = [UIImage imageNamed:imageName];
    }else{
        img = [UIImage imageNamed:[NSString stringWithFormat:@"iphone_%@",imageName]];
    }
    return img;
}

+(UIImage *)imageWithKey:(NSString *)key{
    BOOL flag = [[UserDefaultsUtil shareInstance]getBool:SKIN_SWITCH];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"Skin" ofType:@"plist"]];
    if (dict == nil) {
        return nil;
    }
    
    NSDictionary *skinDict;
    if (flag) {
        if ([DeviceTypeJudge isPadDeviceType]) {
            skinDict = dict[@"wdblue"];
        }else{
           skinDict = dict[@"iphone_wdblue"];
            
        }
    }else{
        if ([DeviceTypeJudge isPadDeviceType]) {
          skinDict = dict[@"hlblue"];
        }else{
            skinDict = dict[@"iphone_hlblue"];
        }
        
    }
    NSString *imgStr = skinDict[key];
    return [UIImage imageNamed:imgStr];
}
@end
